package com.wf.service.impl;

import com.wf.domain.User;
import com.wf.mapper.UserMapper;
import com.wf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author mpk
 * @since 2024/8/20 21:09:22
 */
@Service
public class UserServiceImpl implements UserService {


    @Autowired
    UserMapper userMapper;
    @Override
    public User saveUser(User user) {
        User user1 = userMapper.selectByPrimaryKey(user.getId());
        if (user1 == null) {
            userMapper.insert(user);
            return user;
        } else {
            userMapper.updateByPrimaryKeySelective(user);
            return user1;
        }

    }

    @Override
    public User updateProfilePic(Long id, MultipartFile pic) {
        User user = null;
        if (pic != null) {
            user = userMapper.selectByPrimaryKey(id);
            user.setPic(pic.getOriginalFilename());
            userMapper.updateByPrimaryKeySelective(user);
        }
        return user;
    }

    @Override
    public boolean deleteUser(Long id) {
        return userMapper.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public List<User> findUsersByNameContaining(String name) {
        return null;
    }
}
